package model

import (
	"fmt"
	"nt-order/common"
	"nt-order/conf"
	"time"
)

type AccountLogic struct {
}

func (m *AccountLogic) GetAmazonShopAreaByShopId(shopId int) string {
	redis := conf.GetRedis()
	redisKey := common.GetCacheKey(fmt.Sprintf("ORDER_AMAZON_AREA_%d", shopId))
	data, err := redis.Get(redisKey)
	if err != nil {
		db := conf.GetDb("amazon")
		area := make(map[string]string)
		get, err := db.Table("amazon_account").Where("dp_id=?", shopId).Get(&area)
		if err != nil {
			panic(err)
		}
		data, ok := area["dp_id"]
		if get && ok {
			err := redis.Set(redisKey, data, 72*3600*24*time.Second)
			if err != nil {
				panic(err)
			}
		} else {
			return ""
		}
	}
	return data

}
